package com.pengweiwei.androidzygote;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.putong35.common.account.ui.LoginActivity;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;


/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginActivityTest {

    @Rule
    public ActivityTestRule<LoginActivity> mActivityRule = new ActivityTestRule<>(
            LoginActivity.class);

    @Test
    public void testLogin() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();
        onView(ViewMatchers.withHint(R.string.login_account_input_hint))
                .perform(ViewActions.clearText(), ViewActions.typeText("15959645896"),
                        ViewActions.closeSoftKeyboard());

        onView(ViewMatchers.withHint(R.string.login_input_pwd_hint))
                .perform(ViewActions.clearText(), ViewActions.typeText("12345"),
                        ViewActions.closeSoftKeyboard());

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        onView(ViewMatchers.withId(R.id.btnLogin))
                .perform(ViewActions.click());
    }
}
